<template>
  <div>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item :label="$t('m.bpm.entity.processDefName')">
              <a-input placeholder="" v-model="queryParam.processDefName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item :label="$t('m.bpm.entity.taskTitle')">
              <a-input placeholder="" v-model="queryParam.taskTitle"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item :label="$t('m.bpm.entity.taskType')">
                <a-select v-model="queryParam.taskType" placeholder="">
                  <a-select-option value="all">{{this.$t('m.common.label.all')}}</a-select-option>
                  <a-select-option value="1">{{$t('m.bpm.other.option_todo')}}</a-select-option>
                  <a-select-option value="2">{{$t('m.bpm.other.option_todoed')}}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('m.common.button.query') }}</a-button>
              <a-button type="default" @click="searchReset" icon="reload" style="margin-left: 8px">{{ $t('m.common.button.reset') }}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? this.$t('m.common.button.fold') : this.$t('m.common.button.expand') }}
                <ych-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="batchReReDelegateTask" type="primary"  icon="delete">{{$t('m.bpm.other.cancelDelegate')}}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot="serialNum" slot-scope="text,record,index">
          {{(ipagination.current-1) * ipagination.pageSize + parseInt(index) + 1}}
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">{{ $t('m.common.button.open') }}</a>
        </span>

      </a-table>
    </div>

    <redirect-modal ref="flowForm" @refreshParent="modalFormOk"></redirect-modal>
  </div>
</template>

<script>

  import {YcListMixin} from '@/mixins/YcListMixin';
  import {putAction} from '@/api/manage';
  import RedirectModal from '../../redirect/RedirectModal';
  import YchConstant from "@/api/YchConstant";

  export default {
    name: "DelegateTaskList",
    mixins: [YcListMixin],
    components: {
      RedirectModal,
    },
    data() {
      return {
        description: this.$t('m.bpm.other.my_delegated_tasks_title'),
        // 表头
        columns: [
          {
            title:this.$t('m.common.label.number'),
            dataIndex: '',
            key: 'rowIndex',
            width: "50px",
            align: "center",
            scopedSlots: { customRender: 'serialNum' },
          },
          {
            title: this.$t('m.bpm.entity.processDefName'),
            align: "center",
            width: "150px",
            dataIndex: 'processDefName'
          },
          {
            title: this.$t('m.bpm.entity.taskTitle'),
            align: "left",
            dataIndex: 'taskTitle',
            ellipsis: true,
          },
          /*{
            title: '优先级',
            align: "center",
            dataIndex: 'priority',
            width: 80
          },*/
          {
            title: this.$t('m.bpm.entity.taskType'),
            align: "center",
            dataIndex: 'identityString',
            width: "90px"
          },
          {
            title: this.$t('m.bpm.entity.assigneeName'),
            align: "center",
            dataIndex: 'assigneeName',
            width: "150px",
            customRender: function (t, r, index) {
              return t + (r.assigneeDeptName ? '/' + r.assigneeDeptName : '');
            }
          },
          /*{
            title: '发送人',
            align: "center",
            dataIndex: 'fromUserName',
            width: "150px",
            customRender: function (t, r, index) {
              return t + (r.fromDeptName ? '/' + r.fromDeptName : '');
            }
          },*/
          {
            title: this.$t('m.bpm.entity.sendTimeString'),
            align: "center",
            dataIndex: 'sendTimeString',
            width: "130px"
          },
          {
            title: this.$t('m.bpm.entity.endTimeString'),
            align: "center",
            dataIndex: 'endTimeString',
            width: "130px"
          },
          {
            title: this.$t('m.bpm.entity.dueDateString'),
            align: "center",
            dataIndex: 'dueDateString',
            width: "130px"
          },
          {
            title: this.$t('m.common.label.operate'),
            dataIndex: 'action',
            align: "center",
            scopedSlots: {customRender: 'action'},
            width: "90px"
          }
        ],
        url: {
          list: YchConstant.PREFIX_BPM + "/bpm-front/delegateTaskRest/list/v1",
          batchReReDelegateTask: YchConstant.PREFIX_BPM + "/bpm-front/delegateTaskRest/batchReReDelegateTask/v1",
          /*reDelegateTask: YchConstant.PREFIX_BPM + "/bpm-front/operateRest/reDelegateTask/v1",*/
        }
      }
    },
    inject: ['addRouter'],
    methods: {
      handleDetail(record) {
        let router = null
        if (this.$store.getters.formOpenType === '2') {
          router = this.addRouter({
            path: '/bpm/detailFromTask/' + record.id,
            component: resolve => require(['@/views/bpm/redirect/RedirectTab.vue'], resolve),
            props: {
              id: record.id,
              func: 'detailFromTask',
            },
            meta: {
              title: this.$t('m.bpm.common.bpmDetail'),
            }
          });
          if (router) {
            this.$router.push(router).catch(err => {})
          }
        }
        if (!router) {
          this.$refs.flowForm.detailFromTask(record.id)
        }
      },
      batchReReDelegateTask: function () {
        if (this.selectedRowKeys.length <= 0) {
          this.messageUtil.warning(this.$t('m.common.tip.select_one_warn'));
          return;
        } else {
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          var that = this;
          this.$confirm({
            title: this.$t('m.common.title.operate'),
            content: this.$t('m.bpm.verify.confirm_cancelDelegate'),
            onOk: function () {
              putAction(that.url.batchReReDelegateTask + "?ids=" + ids, {}).then((res) => {
                if (res.success) {
                  that.messageUtil.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.messageUtil.warning(res.message);
                }
              }).finally(() => {
              });
            }
          });
        }
      },
      /*reReDelegateTask(record) {
        var that = this;
        let currentUrl = this.url.reDelegateTask + "?taskId=" + record.id;
        putAction(currentUrl, {}).then((res) => {
          if (res.success) {
            that.messageUtil.success(res.message);
            that.loadData();
          } else {
            that.messageUtil.warning(res.message);
          }
        });
      }*/
    }
  }
</script>
<style lang="less" scoped>
</style>
